<?php

// 团购活动

namespace app\shop\controller;

use think\Db;
use think\Request;
use think\Controller;
use app\shop\model\Ad as AdModel;
use app\shop\model\GoodsType as GoodsTypeModel;
use app\shop\model\GroupGoods as GroupGoodsModel;

class Group extends Controller
{
    /**
     * 团购列表
     * @param GroupGoodsModel $groupGoods
     * @param Request $request
     * @param GoodsTypeModel $goodsType
     * @return mixed
     */
    public function index(Request $request,GoodsTypeModel $goodsType)
    {
        // 商品分类
        $inquire = $request->param();
        // 团购商品

        $ini['sun_group_goods.status'] = 1;
        if (!empty($inquire['tid'])) $ini['sun_shop_goods.goods_str'] = ['like','%,'.$inquire['tid'].',%'];

        $data = Db::view('group_goods','*')->view('shop_goods','goods_str,id,thumb_img,price as old_price,sale_number','shop_goods.id=group_goods.goods_id')->where($ini)->paginate(8,false);

        // 商品分类
        $cate_lists = $goodsType->where('parenTid', 0)->select()->toArray();

        // 广告
        $ad = (new AdModel)->where('parenTid',21)->find();


        return $this->fetch('', [
            'mate_head'  => '天天特价',
            'ad'         => $ad,
            'data'       => $data,
            'cate_lists' => $cate_lists
        ]);
    }
}
